package com.yixun.qfbao.model.enums;

import org.apache.commons.lang.StringUtils;

/**
 * 
 * @author update by zilong.liu
 *	update desc
 *	添加了最大最小值。最大最小值为0，在分销小程序需要做单独处理。因为无卧室在数据库中为无卧室，而不是0，无法统一比较
 */
public enum HuxingEnum {
	UNLIMITED("UNLIMITED", "不限", 0, 0),
	HU_XING_0("无", "0室", 0, 0), 
	HU_XING_1("1", "1室", 0, 2), 
	HU_XING_2("2", "2室", 1, 3), 
	HU_XING_3("3", "3室", 2, 4), 
	HU_XING_4("4","4室", 3, 5), 
	HU_XING_5("5", "5室", 4, 6),
	HU_XING_MORE("5室以上", "5室以上", 5, Integer.MAX_VALUE);

	private String no;
	private String des;
	
	private int min;
	private int max;

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public String getDes() {
		return des;
	}

	public void setDes(String des) {
		this.des = des;
	}
	
	public int getMin() {
		return min;
	}

	public void setMin(int min) {
		this.min = min;
	}

	public int getMax() {
		return max;
	}

	public void setMax(int max) {
		this.max = max;
	}

	HuxingEnum(String no, String des, int min, int max) {
		this.no = no;
		this.des = des;
		this.max = max;
		this.min = min;
	}

	public static HuxingEnum getByNo(String no) {
		if (StringUtils.isBlank(no)) {
			return null;
		}
		for (HuxingEnum menum : values()) {
			if (menum.getNo().equals(no)) {
				return menum;
			}
		}
		return null;
	}

	public static String getNameByCode(String code) {
		if (!StringUtils.isEmpty(code)) {
			HuxingEnum anEnum = getByNo(code);
			if (anEnum != null) {
				return anEnum.getDes();
			} else {
				return null;
			}
		}
		return null;
	}
	
	public static int getMinByNo(String no) {
		if (StringUtils.isBlank(no)) {
			return -1;
		}
		for (HuxingEnum menum : values()) {
			if (menum.getNo().equals(no)) {
				return menum.getMin();
			}
		}
		return -1;
	}
	
	public static int getMaxByNo(String no) {
		if (StringUtils.isBlank(no)) {
			return -1;
		}
		for (HuxingEnum menum : values()) {
			if (menum.getNo().equals(no)) {
				return menum.getMax();
			}
		}
		return -1;
	}

}
